package com.zeng.user.management;

import com.sun.jmx.mbeanserver.Introspector;
import com.zeng.user.domain.User;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;

/**
 * @author zyb
 * @date 2021-03-14 11:24
 */
public class UserManagerDemo {
    public static void main(String[] args) throws Exception {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        ObjectName objectName = new ObjectName("com.zeng.user.management:type=user");
        User user = new User();
        mBeanServer.registerMBean(getMBean(user), objectName);
        while (true) {
            Thread.sleep(2000);
            System.out.println(user);
        }

    }

    private static Object getMBean(User user)throws Exception {
        return Introspector.makeDynamicMBean(new UserManager(user));
    }
}
